package cn.netjava.robo3d.actions;

import cn.netjava.robo3d.RoboTank;

import com.jme.input.InputHandler;
import com.jme.input.action.InputActionEvent;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;

public class CaseMateLeftRightAction extends InputHandler {

	public static int left=1;
	public static int right=-1;
	private int direction;
	private float turnspeed;
    private Vector3f upAxis=new Vector3f(0,1,0) ;
	 //temporary variables to handle rotation
    //the node to manipulate
    private RoboTank car;
    
    public CaseMateLeftRightAction(RoboTank car,int direction){
    	this.direction=direction;
        this.car = car;
        this.turnspeed = 0.6f;
    }
    /**
    * <code>performAction</code> rotates the camera about it's up vector or
    * lock axis at a speed of movement speed * time. Where time is the time
    * between frames and 1 corresponds to 1 second.
    *
    * @see com.jme.input.action.KeyInputAction#performAction(InputActionEvent)
    */
   public void performAction(InputActionEvent evt) {
       //we want to turn differently depending on which direction we are traveling in.
   	   Quaternion carqua=new Quaternion();
   	   float step=0;
		        step=direction*turnspeed*evt.getTime();
                car.addcaseAlpha(step);
                //这是相对车体旋转
                carqua.fromAngleNormalAxis(car.getcaseAlpha(), upAxis);
		        car.getcasemate().setLocalRotation(carqua);
		        car.getcasemate().getLocalRotation().normalize();
   	}
}
